<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
class FgcmsCheckoutPayment {
	var $db;
 	var $smarty;	
	public function __construct($db, $smarty) {
		//contructor function
		$this->db = $db;
		$this->smarty = $smarty;
	}
	
	public function view_payment() {
		$information = FgcmsCustomerBean::getCustomerById($this->db,$_SESSION['cust_id']);	
		$allcountry = FgcmsCountryBean::get_all_country($this->db);	
		$method = FgcmsCheckoutBean::get_all_shipping_method($this->db);
		$incoming_order = FgcmsCheckoutBean::get_incoming_order($this->db,$_SESSION['cust_id']);
		
		$this->smarty->assign("SALESORDER", $information);
		$this->smarty->assign("SHIPPINGMETHOD", $method);
		$this->smarty->assign('ALLCOUNTRY',$allcountry);
		
	}
	
	/*
	 *save customer billing address
	 *
	 */
	public function save_payment_address() {
			$country = FgcmsCountryBean::get_country_byId($this->db,$_POST["billing_country"]);	
			$billing = array('billing_gender' => $_POST["billing_gender"],
					  	  'billing_firstname' => $_POST["billing_firstname"],
						  'billing_lastname' => $_POST["billing_lastname"],
						  'billing_company' => $_POST["billing_company"],
						  'billing_street_address' => $_POST["billing_street_address"],
						  'billing_city' => $_POST["billing_city"],
						  'billing_postcode' => $_POST["billing_postcode"],
						  'billing_state' => $_POST["billing_state"],
						  'billing_country' => $_POST["billing_country"],
						  'billing_country_name' => $country->country_name,
						  'billing_telephone' => $_POST["billing_telephone"],
						  'billing_email_address' => $_POST["billing_email_address"]);	
			//update customer billing address	
			FgcmsCustomerBean::updateCustomerBilling($this->db,$billing);	  		  
		//}	
		header("Location: ./?page=checkout_payment");	
	}//end func
	
	/*
	 *save payment
	 *
	 */	
	public function save_payment() {
		if($_POST["payment_method"] != "") {
			$_SESSION['billing']['payment_method'] = $_POST["payment_method"];
			header("Location: ./?page=checkout_order_confirm");	
		} else {
			$message = 'color:#FF0000';
			setcookie("message", $message,time()+5);
			header("Location: ./?page=checkout_payment");	
		}	
	}//end func
}
?>
